import { Context } from 'hono'
import { prisma } from '../config/sqlite_db'
import { isEmpty, jsonOK, paramErrorJson } from '../utils/tools'
// import { genToken, mathPassword } from '../utils/tools'


export const getTransactionRecordList = async (c: Context) => {
  const lists = await prisma.transactionRecord.findMany()
  return c.json(jsonOK(lists))
}



export const createTransactionRecord = async (c: Context) => {
  const { buy_taining_room, taining_room, num } = await c.req.json()

  if (!buy_taining_room || !taining_room || !num) {
      return c.json(paramErrorJson("params is error"))
  }
  
  const record = await prisma.transactionRecord.create({
    data: {
      buy_taining_room,
      taining_room,
      num,
      ctime: Date.now(),
      utime: Date.now(),
    },
  })

  // const token = await genToken(user.id.toString())
  return c.json(jsonOK(record))
}